const refereeModel = require('../models/referees.js')

class RefereesCtrl {

    async list() {
        let lst = await refereeModel.find().sort('id');
        return lst.map(m=>m.toJSON());
    }

    async create(refereeData) {
        let referee = new refereeModel(refereeData);
        const a = await referee.save();
        return a.toJSON();
    }

    async retrieve(id) {
        let referee = await refereeModel.findById(id);
        return referee?referee.toJSON(): null;
    }

    async upsert(id, refereeData) {
        refereeData.id = id;
        let referee = await refereeModel.upsert(id, refereeData);
        return referee.toJSON();
    }
    async removeById(id) {
        await refereeModel.removeById(id);
        return 1;
    }
}

module.exports = new RefereesCtrl();